package com.bytedance.framwork.core.monitor;

import android.text.TextUtils;

import com.bytedance.frameworks.core.a.e;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.LinkedList;

public class a {
    public static final class a$a {
        String a;
        long b;
        long c;
        String d;
        String e;
        String f;
        int g;
        JSONObject h;

        public a$a(String arg1, long arg2, long arg4, String arg6, String arg7, String arg8, int arg9, JSONObject arg10) {

            this.a = arg1;
            this.b = arg2;
            this.c = arg4;
            this.d = arg6;
            this.e = arg7;
            this.f = arg8;
            this.g = arg9;
            this.h = arg10;
        }
    }

    public static final class b {
        String a;
        JSONObject b;

        public b(String arg1, JSONObject arg2) {

            this.a = arg1;
            this.b = arg2;
        }
    }

    public static final class c {
        String a;
        String b;
        float c;
        boolean d;
        String e;

        public c(String arg1, String arg2, float arg3, boolean arg4, String arg5) {

            this.a = arg1;
            this.b = arg2;
            this.c = arg3;
            this.d = arg4;
            this.e = arg5;
        }
    }

    public static final class d {
        String a;
        int b;
        JSONObject c;
        JSONObject d;

        public d(String arg1, int arg2, JSONObject arg3, JSONObject arg4) {

            this.a = arg1;
            this.b = arg2;
            this.c = arg3;
            this.d = arg4;
        }
    }

    public final LinkedList a;
    public int b;
    private static volatile a c;
    private final LinkedList d;
    private final LinkedList e;
    private final LinkedList f;
    private boolean g;

    public a() {

        this.d = new LinkedList();
        this.e = new LinkedList();
        this.a = new LinkedList();
        this.f = new LinkedList();
        this.b = 100;
    }

    public final void a(d arg4) {
        LinkedList v1 = this.e;
        synchronized (v1) {
            if (this.e.size() > this.b) {
                this.e.poll();
            }

            this.e.add(arg4);
        }
    }

    public static a a() {
        if (c == null) {
            Class v1 = a.class;
            synchronized (v1) {
                if (c == null) {
                    c = new a();
                }
            }
        }
        return c;
    }

    static LinkedList a(a arg1) {
        return arg1.d;
    }

    static void a(b arg2) {
        if (arg2 != null && !TextUtils.isEmpty(arg2.a)) {
            android.support.design.a.a(arg2.a, arg2.b);
        }
    }

    public final void a(c arg4) {
        LinkedList v1 = this.d;
        synchronized (v1) {
            if (this.d.size() > this.b) {
                this.d.poll();
            }
            this.d.add(arg4);
        }
    }

    public final void a(a$a arg4) {
        LinkedList v1 = this.f;
        synchronized (v1) {
            if (this.f.size() > this.b) {
                this.f.poll();
            }

            this.f.add(arg4);
        }
    }

    static LinkedList b(a arg1) {
        return arg1.e;
    }

    static void b(a$a arg9) {
        if (arg9 != null && !TextUtils.isEmpty(arg9.a)) {
            if (arg9.a.equals("api_error")) {
                android.support.design.a.b(arg9.b, arg9.c, arg9.d, arg9.e, arg9.f, arg9.g, arg9.h);
            } else if (arg9.a.equals("api_all")) {
                android.support.design.a.a(arg9.b, arg9.c, arg9.d, arg9.e, arg9.f, arg9.g, arg9.h);
            }
        }
    }

    static void b(c arg10) {
        com.bytedance.frameworks.core.a.e.a v0_3 = null;
        HashMap v8;
        long v6;
        String v5;
        e v4;
        float v3;
        String v2;
        String v1;
        if (arg10 != null && !TextUtils.isEmpty(arg10.a) && !TextUtils.isEmpty(arg10.b) && !TextUtils.isEmpty(arg10.e)) {
            if (arg10.e.equalsIgnoreCase("timer")) {
                if (arg10.d) {
                    android.support.design.a.b(arg10.a, arg10.b, arg10.c);
                    return;
                }

                android.support.design.a.c(arg10.a, arg10.b, arg10.c);
                return;
            }

            if (arg10.e.equals("counter")) {
                if (arg10.d) {
                    android.support.design.a.a(arg10.a, arg10.b, arg10.c);
                    return;
                }

                v1 = arg10.a;
                v2 = arg10.b;
                v3 = arg10.c;
                try {
                    if (com.bytedance.framwork.core.monitor.c.j() == null) {
                        a().a(new c(v1, v2, v3, false, "counter"));
                        return;
                    }

                    if (!android.support.design.a.o(v1)) {
                        return;
                    }

                    if (android.support.design.a.e() == null) {
                        return;
                    }

                    if (!android.support.design.a.f()) {
                        return;
                    }

                    com.bytedance.frameworks.core.a.b.b$a v0_1 = android.support.design.a.e();
                    if (v0_1.a == null) {
                        return;
                    }

                    if (TextUtils.isEmpty(((CharSequence) v1))) {
                        return;
                    }

                    if (TextUtils.isEmpty(((CharSequence) v2))) {
                        return;
                    }

                    v4 = v0_1.a;
                    if (TextUtils.isEmpty(((CharSequence) v1))) {
                        return;
                    }

                    if (TextUtils.isEmpty(((CharSequence) v2))) {
                        return;
                    }

                    v5 = v2 + v1;
                    v6 = System.currentTimeMillis() / 1000;
                    v8 = v4.a;
                    synchronized (v8) {
                        Object v0_2 = v4.a.get(v5);
                        if (v0_2 == null) {
                            v0_3 = new com.bytedance.frameworks.core.a.e.a(v2, v1, v6);
                            v4.a.put(v5, v0_3);
                        }

                        v0_3.c += v3;
                        return;
                    }
                } catch (Throwable v0) {

                }
            }

            if (arg10.e.equals("store")) {
                v1 = arg10.a;
                v2 = arg10.b;
                v3 = arg10.c;
                try {
                    if (com.bytedance.framwork.core.monitor.c.j() == null) {
                        a().a(new c(v1, v2, v3, false, "store"));
                        return;
                    }

                    if (!android.support.design.a.o(v1)) {
                        return;
                    }

                    if (android.support.design.a.e() == null) {
                        return;
                    }

                    if (!android.support.design.a.f()) {
                        return;
                    }

                    android.support.design.a.e().a(v1, v2, v3);
                } catch (Throwable v0) {
                }
            }
        }
    }

    static void b(d arg4) {
        if (arg4 != null && !TextUtils.isEmpty(arg4.a)) {
            android.support.design.a.a(arg4.a, arg4.b, arg4.c, arg4.d);
        }
    }

    public final void b() {
        if (com.bytedance.framwork.core.monitor.c.j() != null && !this.g) {
            this.g = true;
            new com.bytedance.framwork.core.monitor.b(this, "handle_cache_monitor_data").start();
        }
    }

    static LinkedList c(a arg1) {
        return arg1.a;
    }

    static LinkedList d(a arg1) {
        return arg1.f;
    }
}

